const cheerio = require("cheerio");
const fs = require("fs")
/**
 * 
 * @param {string} html html 文本
 */
function htmlToMarkdown (html) {
    html = html.replace(/\u0000/g, "")
    // 解析
    const $ = cheerio.load(html);
    // 获取标题
    let title = $("body > a > h1").text();
    title = title ? title : "";
    let tag = $("body > a > div:nth-child(2) > table > tbody > tr > td:nth-child(2) > i").text();
    tag = tag ? tag : "";

    // 开始遍历各个节点
    let content = $("body > a > div > span");
    if (content.length == 0) {
        content = $("body > div");
    }
    let rootList = content.children();
    let st = []
    for(let i=0;i<rootList.length;i++){
        let rootItem = rootList[i]
        st.push(rootItem)
        // 深度优先搜索
        while(st.length>0){
            let root = st.pop()
            //检查是不是单一节点
            console.log()
        }
    }
}


let html = fs.readFileSync("./素材/测试——超级笔记.html","utf-8")
htmlToMarkdown(html)